﻿using System.Windows.Browser;
using System.Windows.Controls;

namespace Html5Canvas
{
    // Implements the HTMLCanvasElement interface
    public class HTMLCanvasElement
    {
        private Canvas _canvas;
        private CanvasRenderingContext2D _canvasRenderingContext;

        public HTMLCanvasElement(Canvas canvas)
        {
            // Wrap the provided canvas
            _canvas = canvas;
        }

        [ScriptableMember]
        public CanvasRenderingContext2D getContext(string context)
        {
            // Create new CanvasRenderingContext2D if needed
            CanvasRenderingContext2D canvasRenderingContext = null;
            if (0 == string.CompareOrdinal("2d", context))
            {
                if (null == _canvasRenderingContext)
                {
                    _canvasRenderingContext = new CanvasRenderingContext2D(_canvas);
                }
                canvasRenderingContext = _canvasRenderingContext;
            }
            return canvasRenderingContext;
        }
    }
}
